// struct 体中使用泛型：
struct Point<T> {
    x: T,
    y: T,
}

fn struct_generic() {
    let inter = Point { x: 5, y: 6 };
    let float = Point { x: 1.0, y: 53.0 };
}

struct Point1<T, U> {
    x: T,
    y: U,
}

fn struct_generic1() {
    let inter = Point1 { x: 5, y: 6.0 };
    let float = Point1 { x: 1.0, y: 53.0 };
}

// Enum 中使用泛型
enum Option<T> {
    Some(T),
    None,
}

enum Result<T, E> {
    Ok(T),
    Err(E),
}

// 方法定义中使用泛型
impl<T> Point<T> {
    fn x(&self) -> &T {
        &self.x
    }
}

pub fn invoke_point() {
    let p = Point { x: 5, y: 10 };
    println!("{}", p.x());
}

impl<T, U> Point1<T, U> {
    fn mix_up<V, W>(self, other: Point1<V, W>) -> Point1<T, W> {
        Point1 {
            x: self.x,
            y: other.y,
        }
    }
}

pub fn invoke_mixup() {
    let p1 = Point1 { x: 5, y: 10 };
    let p2 = Point1 { x: "Hello", y: 'c' };
    let p3 = p1.mix_up(p2);

    println!("p3.x: {}, p3.y: {}", p3.x, p3.y);
}
